<?php
/**
 * 2017年6月7日18:31:03
 * PDO SAFE
 */

include 'common.php';
$username = $_COOKIE['username'];
$token = $_COOKIE['token'];
$ctime = $_REQUEST['time'];
$loctype= $_REQUEST['loctype'];
$citycode= $_REQUEST['citycode'];
$cityname= $_REQUEST['cityname'];
$operators= $_REQUEST['operators'];
$radius = $_REQUEST['radius'];
$fingerprint= $_REQUEST['fingerprint'];
$lan = $_REQUEST['lan'];
$lon = $_REQUEST['lon'];
$uuid = $_REQUEST['uuid'];

$dbc = pdo_root_connect();

$stmt = $dbc->prepare('select * from userinfo where username=? and token=? and status=1');
$stmt->execute(array($username, $token));
if($stmt->rowCount() == 0){
	$username = 'ANONYMOUS';
}

if(!is_null($uuid) && $uuid != ''){
/* 	$result2 = mysql_query("insert into userloction (username, updatetime, uploadtime, loctype, citycode, cityname, operators, radius, fingerprint, lan, lon, uuid)
			values ('$username', '$ctime', '$time', '$loctype', '$citycode', '$cityname', '$operators', '$radius', '$fingerprint', '$lan', '$lon', '$uuid')", $conn);
 */
	$stmt2 = $dbc->prepare('insert into userloction (username, updatetime, uploadtime, loctype, citycode, 
	cityname, operators, radius, fingerprint, lan, lon, uuid) values(:username, :updatetime, unix_timestamp(now()), :loctype, :citycode,
	:cityname, :operators, :radius, :fingerprint, :lan, :lon, :uuid)');
	$stmt2->bindParam(':username', $username);
	$stmt2->bindParam(':updatetime', $ctime);
	$stmt2->bindParam(':loctype', $loctype);
	$stmt2->bindParam(':citycode', $citycode);
	$stmt2->bindParam(':cityname', $cityname);
	$stmt2->bindParam(':operators', $operators);
	$stmt2->bindParam(':radius', $radius);
	$stmt2->bindParam(':fingerprint', $fingerprint);
	$stmt2->bindParam(':lan', $lan);
	$stmt2->bindParam(':lon', $lon);
	$stmt2->bindParam(':uuid', $uuid);
	$stmt2->execute();	
	if($stmt2->rowCount() > 0){
		$errorcode = 1;
	}else{
		$errorcode = 0;
	}
	
}
echo json_encode(array('errorcode'=>$errorcode));
?>